package br.ufmg.ubicomp.droidguide.communication;

import org.w3c.dom.NodeList;

import br.ufmg.ubicomp.droidguide.utils.RequestUtil;

public enum HttpRequestProcessor {

	JAVA_NET{
		@Override
		protected NodeList processRequest(String url) throws Exception {
			return RequestUtil.executeUrlDOM(url);
		}
	}, 
	HTTP_CLIENT{
		@Override
		protected NodeList processRequest(String url) throws Exception{
//			DefaultHttpClient client = new DefaultHttpClient();
//			HttpGet method = new HttpGet(url);
//			HttpResponse response = client.execute(method);
//			HttpEntity entity = response.getEntity();			
//			InputStream inStream = entity.getContent();
//			
//			/* Parse XML */		
//			DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
//			Document doc = docBuilder.parse(inStream);
//			// root element.
//			Element root = doc.getDocumentElement();
//			if (root == null)
//			{
//				throw new Exception("XML root is null");
//			}			
//			return root.getChildNodes();
			return null;
		}
	};
	
	
	protected abstract NodeList processRequest(String url) throws Exception;
	
	public static NodeList processRequest(String api, String url) throws Exception
	{
		NodeList entities = null;
		if (api.equals("JAVA_NET"))
		{
			entities = JAVA_NET.processRequest(url);
		} else if (api.equals("HTTP_CLIENT"))
		{
			entities = HTTP_CLIENT.processRequest(url);
		}
		return entities;
		
	}
}
